package com.buercorp.wangyu.core1.ch12.threads;

public class ThreadDaemon {
    //测试守护线程
    //上帝守护着你
    public static void main(String[] args) {
        God god = new God();
        You you = new You();

        Thread thread = new Thread(god);
        thread.setDaemon(true);//默认是false表示是用户线程，正常的线程都是用户线程

        thread.start();//上帝守护线程启动

        new Thread(you).start();
    }

}

//上帝
class God implements Runnable {

    @Override
    public void run() {
        while (true) {
            System.out.println("上帝保护着你");
        }
    }
}

//你
class You implements Runnable {

    @Override
    public void run() {
        for (int i = 0; i < 36500; i++) {
            System.out.println("你一生都是开心的");
        }

        System.out.println("----goodbye you！----");
    }
}

